package srms.the505div1;

public class SetMultiples {

	public long smallestSubset(long a, long b, long c, long d) {
		a = Math.max(b / 2 + 1, a);
		c = Math.max(d / 2 + 1, c);

		long fa = d - c + 2;

		if (fa < a)
			fa = a;

		long r = d - c + 1;

		while (fa <= b) {
			long k = d / fa;
			long na = (c - 1) / k + 1;
			if (na < fa)
				na = fa;
			r += na - fa;
			fa = d / k + 1;
		}
		return r;
	}
}
